/**    
 * @{#} RoleAction.java Create on 2012-6-8 上午12:31:33    
 *    
 * Copyright (c) 2012 by 悠忧虫.    
 *    
 * @author 悠忧虫
 * @version 1.0    
 */
package tk.sunlatus.project.interface4web.action;

import java.util.Arrays;
import java.util.List;

import tk.sunlatus.project.permission.domain.Role;
import tk.sunlatus.project.permission.service.RoleService;
import tk.sunlatus.project.usermanage.domain.User;
import tk.sunlatus.project.usermanage.service.UserService;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @{# RoleAction.java Create on 2012-6-8 上午12:31:33
 * 
 *     类功能说明:
 * 
 *     <p>
 *     Copyright: Copyright(c) 2012
 *     </p>
 * @Version 1.0
 * @Author 悠忧虫
 */
public class RoleAction extends ActionSupport {

    /**
     * serialVersionUID：
     */
    private static final long serialVersionUID = -1833661271306098299L;

    private Role role = null;

    private List<User> userList = null;

    private List<Role> roleList = null;

    private String[] roleUserIDs = null;

    private UserService userService = null;

    private RoleService roleService = null;

    /**
     * 方法描述：跳转到角色管理页面
     * 
     * @return
     */
    public String roleIndex() {
        roleList = roleService.queryRoles(null);
        System.out.println(Arrays.toString(roleList.toArray()));
        return SUCCESS;
    }

    /**
     * 方法描述：添加角色
     * 
     * @return
     */
    public String addRole() {
        roleService.addRole(role);
        return SUCCESS;
    }

    /**
     * 方法描述： 跳转到角色添加页面
     * 
     * @return
     */
    public String toAddRole() {
        userList = userService.queryUserList(null, null);
        return SUCCESS;
    }

    /**
     * 方法描述：跳转到更新页面
     * 
     * @return
     */
    public String toUpdateRole() {
        System.out.println("enter method:toUpdateRole; role=" + role);
        userList = userService.queryUserList(null, null);
        if (role != null) {
            role = roleService.queryByID(role.getId());
        }
        System.out.println("exit method:toUpdateRole; role=" + role);
        return SUCCESS;
    }

    public String updateRole() {
        roleService.addUsers2Role(role, roleUserIDs);
        return SUCCESS;
    }

    /**
     * @return the role
     */
    public Role getRole() {
        return role;
    }

    /**
     * @param role
     *            the role to set
     */
    public void setRole(Role role) {
        this.role = role;
    }

    /**
     * @return the roleService
     */
    public RoleService getRoleService() {
        return roleService;
    }

    /**
     * @param roleService
     *            the roleService to set
     */
    public void setRoleService(RoleService roleService) {
        this.roleService = roleService;
    }

    /**
     * @return the userService
     */
    public UserService getUserService() {
        return userService;
    }

    /**
     * @param userService
     *            the userService to set
     */
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    /**
     * @return the userList
     */
    public List<User> getUserList() {
        return userList;
    }

    /**
     * @param userList
     *            the userList to set
     */
    public void setUserList(List<User> userList) {
        this.userList = userList;
    }

    /**
     * @return the roleUserIDs
     */
    public String[] getRoleUserIDs() {
        return roleUserIDs;
    }

    /**
     * @param roleUserIDs
     *            the roleUserIDs to set
     */
    public void setRoleUserIDs(String[] roleUserIDs) {
        this.roleUserIDs = roleUserIDs;
    }

    /**
     * @return the roleList
     */
    public List<Role> getRoleList() {
        return roleList;
    }

    /**
     * @param roleList
     *            the roleList to set
     */
    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }

}
